<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>订单详情-青鸟优品</title>
    <link rel="stylesheet" href="./assets/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="./assets/css/common.css">
    <script src="./assets/js/jquery.js"></script>
    <script src="./assets/bootstrap/js/bootstrap.min.js"></script>
    <script src="./assets/layer/layer.js"></script>
    <script src="./assets/js/common.js"></script>
    <script src="./assets/js/ucenter.js"></script>
</head>

<body>

    <nav class="navbar navbar-fixed-top">
        <div class="container-fluid">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                    data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="./index.html">青鸟商城</a>
            </div>

            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav navbar-left">
                    <!-- <li class="active"><a href="#">热门推荐 <span class="sr-only">(current)</span></a></li>
                    <li><a href="#">国际品牌</a></li>
                    <li><a href="#">数码电器</a></li>
                    <li><a href="#">智能手机</a></li>
                    <li><a href="#">每日特价</a></li> -->
                </ul>

                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <a href="./ucenter.html">
                            <i class="glyphicon glyphicon-user"></i>
                            个人中心
                        </a>
                    </li>
                    <li>
                        <a href="#">
                            <i class="glyphicon glyphicon-off"></i>
                            安全退出</a>
                    </li>
                </ul>

            </div>
        </div>
    </nav>

    <div class="container user-info">
        <div class="row">
            <div class="col-xs-2">
                <ul class="nav nav-pills nav-stacked ">
                    <div class="avatar">
                        <img src="./uploads/avatar/01.jpg" class="img-circle user-avatar">
                    </div>
                    <hr>
                    <li role="presentation"><a href="./ucenter.html">会员中心</a></li>
                    <li role="presentation" class="active"><a href="./order-list.html">我的订单</a></li>
                    <li role="presentation"><a href="./update-info.html">信息设置</a></li>
                    <li role="presentation"><a href="./reset-pwd.html">重置密码</a></li>
                    <li role="presentation"><a href="./address.html">收货地址</a></li>

                </ul>
            </div>
            <div class="col-xs-10 order-list">

                <table class="table table-bordered">
                    <tr class="active">
                        <td>订单编号</td>
                        <td>支付方式</td>
                        <td>支付状态</td>
                        <td>订单状态</td>
                        <td>订单金额</td>
                        <td>下单时间</td>
                        <td>操作</td>
                    </tr>
                    <tbody id="order-info">

                        <!-- <tr class="cart-item">
                            <td>

                                99316768860

                            </td>
                            <td>
                                <span>在线支付</span>
                            </td>
                            <td>
                                未支付
                            </td>
                            <td>
                                未发货
                            </td>
                            <td>
                                <span class="price">&yen;3999</span>
                            </td>
                            <td>
                                2020-06-12 10:12:10
                            </td>
                            <td>
                                <a class="text-danger">删除</a>
                            </td>
                        </tr> -->
                    </tbody>
                </table>
                <!-- 订单商品 -->
                <table class="table table-bordered">
                    <tr class="active">
                        <td>商品名称</td>
                        <td>商品单价</td>
                        <td>商品数量</td>
                        <td>操作</td>
                    </tr>
                    <tbody id="order-items">

                        
                        <!-- <tr class="cart-item">
                            <td>
                                <div class="media">
                                    <div class="media-left">
                                        <a href="#">
                                            <img src="./uploads/10.png" alt="" style="width: 100px;">
                                        </a>
                                    </div>
                                    <div class="media-body" style="width: 100px;">
                                        珀莱雅活能密集补水保湿套装化妆品套装女士护肤品洁面水乳正品 洁水乳保湿
                                    </div>
                                </div>

                            </td>
                            <td>
                                <span class="price">&yen;3999</span>
                            </td>
                            <td>
                                2
                            </td>
                            <td>
                                <a class="text-danger">查看</a>
                            </td>
                        </tr> -->

                    </tbody>
                </table>


            </div>
        </div>
    </div>


    <div class="container-fluid footer">
        <div class="row">
            <div class="col-lg-12">
                Copyright 2019 by www.braccp.com 北京畅想唯优信息技术有限公司 All rights reserved.
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12">
                联系电话：029-88212666 地址：西安市雁塔区电子一路 石油大学北门工会楼二层
            </div>
        </div>

        <div class="row">
            <div class="col-lg-12">
                备案号：陕ICP备19013769号-1
            </div>
        </div>
    </div>
</body>
<script>
    // 校验登录凭证
    auth();
    // 从url中获取订单id
    var id = location.search.split('=')[1];
    if (!id) {
        layer.msg('参数错误', function () {
            location.href = "/order-list.html"
        });
    } else {
        // 获取订单详情
        $.ajax({
            url: '/apis/index.php?c=order&a=detail',
            data: { id },
            dataType: 'json',
            headers: {
                Token: localStorage.getItem('token')
            }
        }).then(res => {
            console.log(res);
            if(res.errcode===0){
                const data=res.data;
                var order=`
                <tr class="cart-item">
                    <td>${data.order_no}</td>
                    <td>${data.pay_way==1?'在线支付':'货到付款'}</td>
                    <td>${data.pay_status==1?'未支付':'已支付'}</td>
                    <td>${data.status==1?'未发货':'已发货'}</td>
                    <td><span class="price">&yen;${data.amount}</span></td>
                    <td>${data.createtime}</td>
                    <td><a href="#" class="btn btn-danger btn-xs btn-del">删除</a> </td>
                </tr>
                `;
                // 渲染页面
                $("#order-info").html(order);
                var products=``;
                data.items.forEach(item => {
                    products+=`
                    <tr class="cart-item">
                            <td>
                                <div class="media">
                                    <div class="media-left">
                                        <a href="#">
                                            <img src="${item.product_cover}" alt="" style="width: 100px;">
                                        </a>
                                    </div>
                                    <div class="media-body" style="width: 100px;">
                                        ${item.product_name}
                                    </div>
                                </div>
                            </td>
                            <td><span class="price">&yen;${item.product_price}</span></td>
                            <td>${item.product_num}</td>
                            <td><a title="点击查看商品详情" target="_blank" href="/detail.html?id=${item.product_id}">查看</a></td>
                        </tr>
                    `;
                });
                // 渲染页面
                $("#order-items").html(products);
            }
        });
    
    
        // 订单删除
        $("#order-info").on('click','.btn-del',function(){
            if(!confirm('确认删除?')){
                return false;
            }
            // 发送请求
            $.ajax({
                url:'/apis/index.php?c=order&a=del',
                data:{id},
                dataType:'json',
                headers:{
                    Token:localStorage.getItem('token')
                }
            }).then(res=>{
                if(res.errcode===0){
                    // 重定向到订单列表页
                    layer.msg('订单删除成功',()=>{
                        location.href="/order-list.html";
                    });
                }else{
                    layer.msg('删除失败, 请稍后重试');
                }
            })
        });
    
    }


</script>

</html>